package com.sweets.look.ui.browser;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class WebAddress {
    private static final int MATCH_GROUP_AUTHORITY = 2;
    private static final int MATCH_GROUP_HOST = 3;
    private static final int MATCH_GROUP_PATH = 5;
    private static final int MATCH_GROUP_PORT = 4;
    private static final int MATCH_GROUP_SCHEME = 1;
    private static final Pattern sAddressPattern = Pattern.compile("(?:(http|https|file)\\\\:\\\\/\\\\/)?(?:([-A-Za-z0-9$_.+!*'(),;?&=]+(?:\\\\:[-A-Za-z0-9$_.+!*'(),;?&=]+)?)@)?([a-zA-Z0-9��-������-������-���%_-][a-zA-Z0-9��-������-������-���%_\\.-]*|\\[[0-9a-fA-F:\\.]+\\])?(?:\\\\:([0-9]*))?(\\\\/?[^#]*)?.*", 2);
    private String mAuthInfo;
    private String mHost;
    private String mPath;
    private int mPort;
    private String mScheme;

    public WebAddress(String address) {

        super();
        int v6 = 443;
        char v4 = '/';
        int v5 = -1;

        if (address == null) {
            throw new IllegalArgumentException("address can\'t be null");
        }

        this.mScheme = "";
        this.mHost = "";
        this.mPort = v5;
        this.mPath = "/";
        this.mAuthInfo = "";
        Matcher v1 = WebAddress.sAddressPattern.matcher(((CharSequence) address));
        if (!v1.matches()) {
            throw new IllegalArgumentException("Parsing of address \'" + address + "\' failed");
        }

        String v2 = v1.group(1);
        if (v2 != null) {
            this.mScheme = v2.toLowerCase(Locale.ROOT);
        }

        v2 = v1.group(2);
        if (v2 != null) {
            this.mAuthInfo = v2;
        }

        v2 = v1.group(3);
        if (v2 != null) {
            this.mHost = v2;
        }

        v2 = v1.group(4);
        if (v2 != null && !v2.isEmpty()) {
            try {
                this.mPort = Integer.parseInt(v2);
            } catch (NumberFormatException v0) {
                throw new RuntimeException("Parsing of port number failed", ((Throwable) v0));
            }
        }

        v2 = v1.group(5);
        if (v2 != null && !v2.isEmpty()) {
            this.mPath = v2.charAt(0) == v4 ? v2 : v4 + v2;
        }

        if (this.mPort == v6 && ("".equals(this.mScheme))) {
            this.mScheme = "https";
        } else if (this.mPort == v5) {
            this.mPort = "https".equals(this.mScheme) ? v6 : 80;
        }

        if ("".equals(this.mScheme)) {
            this.mScheme = "http";
        }
    }

    public String getAuthInfo() {
        return this.mAuthInfo;
    }

    public String getHost() {
        return this.mHost;
    }

    public String getPath() {
        return this.mPath;
    }

    public int getPort() {
        return this.mPort;
    }

    public String getScheme() {
        return this.mScheme;
    }

    public void setAuthInfo(String authInfo) {
        this.mAuthInfo = authInfo;
    }

    public void setHost(String host) {
        this.mHost = host;
    }

    public void setPath(String path) {
        this.mPath = path;
    }

    public void setPort(int port) {
        this.mPort = port;
    }

    public void setScheme(String scheme) {
        this.mScheme = scheme;
    }

    public String toString() {
        String v1 = "";
        if (this.mPort != 443 && ("https".equals(this.mScheme)) || this.mPort != 80 && ("http".equals(
                this.mScheme))) {
            v1 = ':' + Integer.toString(this.mPort);
        }

        String v0 = "";
        if (!this.mAuthInfo.isEmpty()) {
            v0 = this.mAuthInfo + '@';
        }

        return this.mScheme + "://" + v0 + this.mHost + v1 + this.mPath;
    }
}

